package com.prs.crm.action;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

public class DateAction extends BaseAction{

	
	private static final long serialVersionUID = -5052032742465774839L;
	
	private String dateStr;
	
	private String startDate;
	
	private String endDate;

	public void setDateStr(String dateStr) {
		this.dateStr = dateStr;
	}

	public String getDateStr() {
		return dateStr;
	}
	

	 public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public String getStartDate() {
		return startDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public String getEndDate() {
		return endDate;
	}

	@Action(value="getDayOfWeek",results={@Result(name="success",type="json",params={"root","startDate,endDate"})})
	 public  String getDayOfWeek() throws Exception{
		 try
		 {
			 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			 Calendar c = Calendar.getInstance();
			 c.setTime(sdf.parse(dateStr));
			 c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
			 startDate = sdf.format(c.getTime());
			 c.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
			 endDate = sdf.format(c.getTime());
		 }
		 catch (Exception e)
		 {
			 e.printStackTrace();
		 }
		  return SUCCESS;
	 }

	

	 @Action(value="getDayOfMonth",results={@Result(name="success",type="json",params={"root","startDate,endDate"})})
	 public  String getFirstDayOfMonth() throws Exception{
		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		  Calendar c = Calendar.getInstance();
		  c.setTime(sdf.parse(dateStr));
		  c.set(Calendar.DAY_OF_MONTH,  c.getActualMinimum(Calendar.DAY_OF_MONTH));
		 
		  startDate = sdf.format(c.getTime());
		  c.set(Calendar.DAY_OF_MONTH,  c.getActualMaximum(Calendar.DAY_OF_MONTH));
		  endDate = sdf.format(c.getTime());
		  return SUCCESS;
	 }



}
